package com.alasbusy.alasbusyapp.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.alasbusy.alasbusyapp.R;

/**
 * Created by Administrator on 2017/11/3.
 */

public abstract class BaseFragment extends Fragment {


    private View mBack;
    private TextView mTitle;
    private View mTitle_image;
    private TextView title_right_txt;
    /*
    加载布局
     */
    public abstract int getLayout();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View mView = View.inflate(getActivity(), getLayout(), null);
        initView(mView);
        initData();
        initListener();
        return mView;
    }

    public void getVisibility(boolean visi, final Activity activity){
        if(visi) {
            mBack.setVisibility(View.VISIBLE);
            mBack.setEnabled(true);
            mBack.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    activity.finish();
                }
            });
        }else {
            mBack.setVisibility(View.INVISIBLE);
            mBack.setEnabled(false);
        }
    }

    public void setTop(View view){
        mBack = view.findViewById(R.id.back);
        mTitle = (TextView) view.findViewById(R.id.title);
        mTitle_image = view.findViewById(R.id.title_image);
        title_right_txt = (TextView) view.findViewById(R.id.title_right_txt);
    }

    public void getTitle(String title){
        mTitle.setText(title);
    }

    /*
   初始化控件
    */
    protected abstract void initView(View view);

    /*
    初始化数据
     */
    protected abstract void initData();

    /*
    设置监听事件
     */
    protected abstract void initListener();

}
